import axios from 'axios';
import { Toast } from 'vant';

let toast = null;
// 创建axios实例
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 10000,
});
// 过滤请求
service.interceptors.request.use((config) => {
  if (!toast) {
    toast = Toast.loading({
      forbidClick: true,
      loadingType: 'spinner',
      duration: 0,
    });
  }
  return config;
});
// 过滤响应
service.interceptors.response.use((result) => {
  if (toast) {
    toast.clear();
    toast = null;
  }
  return result;
});

export default service;
